package com.edu.exam.entity.grading.export;

import com.edu.exam.entity.core.AuditableEntity;
import com.edu.exam.enums.grading.ExportConfigType;
import com.edu.exam.enums.grading.ExportDataType;
import com.edu.exam.enums.grading.BusinessImpactLevel;
import com.edu.exam.enums.grading.ExportSecurityLevel;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 成绩导出配置表实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：grade_export_config</p>
 *
 * <p>成绩导出系统配置管理表，用于管理成绩导出系统的各种配置参数。
 * 支持全局配置、模块配置、性能配置、安全配置等多维度的配置管理，
 * 包含配置版本控制、变更历史、动态更新等功能。</p>
 *
 * @author 系统生成
 * @version 1.0
 * @since 2025-11-10
 */
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
public class GradeExportConfig extends AuditableEntity {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

    /**
     * 配置键值
     */
    @Column(name = "config_key", nullable = false, unique = true, length = 100)
    String configKey;

    /**
     * 配置名称
     */
    @Column(name = "config_name", nullable = false, length = 100)
    String configName;

    /**
     * 配置类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "config_type", nullable = false, length = 30)
    ExportConfigType configType;

    /**
     * 配置分组
     */
    @Column(name = "config_group", length = 50)
    String configGroup;

    /**
     * 配置值
     */
    @Column(name = "config_value", columnDefinition = "TEXT")
    String configValue;

    /**
     * 默认值
     */
    @Column(name = "default_value", columnDefinition = "TEXT")
    String defaultValue;

    /**
     * 配置描述
     */
    @Column(name = "description", length = 500)
    String description;

    /**
     * 数据类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "data_type", length = 20)
    ExportDataType dataType;

    /**
     * 配置值格式
     */
    @Column(name = "value_format", length = 50)
    String valueFormat;

    /**
     * 验证规则
     */
    @Column(name = "validation_rules", columnDefinition = "TEXT")
    String validationRules;

    /**
     * 取值范围
     */
    @Column(name = "value_range", length = 200)
    String valueRange;

    /**
     * 可选值列表
     */
    @Column(name = "allowed_values", columnDefinition = "TEXT")
    String allowedValues;

    /**
     * 配置单位
     */
    @Column(name = "config_unit", length = 20)
    String configUnit;

    /**
     * 配置版本
     */
    @Column(name = "config_version", length = 20)
    String configVersion;

    /**
     * 业务影响级别
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "business_impact_level", length = 20)
    BusinessImpactLevel businessImpactLevel;

    /**
     * 安全级别
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "security_level", length = 20)
    ExportSecurityLevel securityLevel;

    /**
     * 是否激活
     */
    @Column(name = "is_active", nullable = false)
    Boolean isActive;

    /**
     * 是否系统配置
     */
    @Column(name = "is_system", nullable = false)
    Boolean isSystem;

    /**
     * 是否只读
     */
    @Column(name = "is_readonly", nullable = false)
    Boolean isReadonly;

    /**
     * 是否敏感配置
     */
    @Column(name = "is_sensitive", nullable = false)
    Boolean isSensitive;

    /**
     * 是否需要重启
     */
    @Column(name = "requires_restart", nullable = false)
    Boolean requiresRestart;

    /**
     * 是否需要刷新缓存
     */
    @Column(name = "requires_cache_refresh", nullable = false)
    Boolean requiresCacheRefresh;

    /**
     * 优先级
     */
    @Column(name = "priority")
    Integer priority;

    /**
     * 环境限制
     */
    @Column(name = "environment", length = 50)
    String environment;

    /**
     * 应用限制
     */
    @Column(name = "application_scope", length = 200)
    String applicationScope;

    /**
     * 用户限制
     */
    @Column(name = "user_restrictions", length = 200)
    String userRestrictions;

    /**
     * 扩展属性
     */
    @Column(name = "extended_attributes", columnDefinition = "TEXT")
    String extendedAttributes;

    /**
     * 最后修改时间
     */
    @UpdateTimestamp
    @Column(name = "last_modified_time", nullable = false)
    LocalDateTime lastModifiedTime;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "creation_time", nullable = false)
    LocalDateTime creationTime;
}